import java.util.Random;

/**
 * @Title: Four
 * @Author kerry
 * @Package PACKAGE_NAME
 * @Date 2024/11/21 23:17
 */

public class Four {
    public static void main(String[] args) {
        School school = new School();
        System.out.println(school.getName());

        System.out.println("=======");
        Employee[] staff = new Employee[3];

         staff[0] = new Employee("harry",500);
         staff[1] = new Employee(60000);
         staff[2] = new Employee();
        for (Employee employee : staff) {
            System.out.println(employee.getId());
            System.out.println(employee);
        }
    }

    // 方法重载操作

    public void t(int num){}
    public void t(int num,String s){}
    public String t(int num,int s) {
        return "hello";
    }
}


class School {
    private String name = "嘻嘻";
    private String address;
    private int age;

    {
        name = "哈哈哈";
        System.out.println("普通代码块 ~ "+name);
    }

    public School(){
        this("啦啦");
    }

    public School(String name) {
        this.name = name;
        System.out.println("构造方法 ~ "+name);
    }

    public String getName() {
        return name;
    }
}


// 书中的例子

class Employee {
    private static int nextId;
    private int id;
    private String name = "";
    private double salary;

    static {
        Random random = new Random();
        nextId = random.nextInt(1000);
    }

    {
        id = nextId;
        nextId++;
    }

    public Employee() {}

    public Employee(String n,double s) {
        name = n;
        salary = s;
    }

    public Employee(double s) {
        this("Employee #"+nextId,s);
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", salary=" + salary +
                '}';
    }
}